"use strict";
cc._RF.push(module, 'ff5f8f/CqNOH5gfQbiVhjvH', 'TouchBlocker');
// eazax-ccc/components/TouchBlocker.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
/**
 * 点击屏蔽器组件
 * @see TouchBlocker.ts https://gitee.com/ifaswind/eazax-ccc/blob/master/components/TouchBlocker.ts
 * @version 20210421
 */
var TouchBlocker = /** @class */ (function (_super) {
    __extends(TouchBlocker, _super);
    function TouchBlocker() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.target = null;
        /** 拦截状态 */
        _this.isBlockAll = false;
        /** 放行状态 */
        _this.isPassAll = false;
        return _this;
    }
    TouchBlocker.prototype.onLoad = function () {
        this.registerEvent();
    };
    TouchBlocker.prototype.start = function () {
        this.reset();
    };
    TouchBlocker.prototype.onDestroy = function () {
        this.unregisterEvent();
    };
    /**
     * 订阅事件
     */
    TouchBlocker.prototype.registerEvent = function () {
        this.node.on(cc.Node.EventType.TOUCH_START, this.onTouchEvent, this);
        this.node.on(cc.Node.EventType.TOUCH_MOVE, this.onTouchEvent, this);
        this.node.on(cc.Node.EventType.TOUCH_END, this.onTouchEvent, this);
    };
    /**
     * 移除订阅事件
     */
    TouchBlocker.prototype.unregisterEvent = function () {
        this.node.targetOff(this);
    };
    /**
     * 重置
     */
    TouchBlocker.prototype.reset = function () {
        // 取消吞噬事件
        this.setSwallowTouches(false);
    };
    /**
     * 事件回调
     * @param event 事件
     */
    TouchBlocker.prototype.onTouchEvent = function (event) {
        // 全部放行状态
        if (this.isPassAll) {
            return;
        }
        // 拦截状态并且无目标
        if (this.isBlockAll || !this.target) {
            event.stopPropagationImmediate();
            return;
        }
        // 点击是否命中目标节点
        var targetRect = this.target.getBoundingBoxToWorld(), isContains = targetRect.contains(event.getLocation());
        if (!isContains) {
            event.stopPropagationImmediate();
        }
    };
    /**
     * 屏蔽所有点击
     */
    TouchBlocker.prototype.blockAll = function () {
        this.isBlockAll = true;
        this.isPassAll = false;
    };
    /**
     * 放行所有点击
     */
    TouchBlocker.prototype.passAll = function () {
        this.isPassAll = true;
        this.isBlockAll = false;
    };
    /**
     * 设置可点击的节点
     * @param node 节点
     */
    TouchBlocker.prototype.setTarget = function (node) {
        this.target = node;
        this.isBlockAll = false;
        this.isPassAll = false;
    };
    /**
     * 设置节点是否吞噬点击事件
     * @param swallow 状态
     */
    TouchBlocker.prototype.setSwallowTouches = function (swallow) {
        this.node._touchListener && this.node._touchListener.setSwallowTouches(swallow);
    };
    __decorate([
        property({ type: cc.Node, tooltip: CC_DEV && '可被点击的节点' })
    ], TouchBlocker.prototype, "target", void 0);
    TouchBlocker = __decorate([
        ccclass
    ], TouchBlocker);
    return TouchBlocker;
}(cc.Component));
exports.default = TouchBlocker;

cc._RF.pop();